CC = sdcc
CFLAGS= -c -mpic16 -p18f97j60 -s 18f97j60.lkr --opt-code-speed -D__SDCC__ -D__18F97J60 $(INCLUDE_PATHS)

LD = sdcc
LDFLAGS= -mpic16 -p18f97j60 -Wl,-s,18f97j60.lkr -L/usr/share/sdcc/non-free/lib/pic16 \
 -L/usr/local/share/sdcc/non-free/lib/pic16 -L/usr/share/sdcc/lib/pic16 -L/usr/local/share/sdcc/lib/pic16 \
-llibio18f97j60.lib -llibdev18f97j60.lib -llibc18f.lib

INCLUDE_PATHS = -I../Include -I./ -I/usr/share/sdcc/include -I/usr/local/share/sdcc/include \
 -I/usr/share/sdcc/non-free/include/pic16 -I/usr/local/share/sdcc/non-free/include/pic16 \
 -I/usr/share/sdcc/include/pic16

all: announce.o arp.o delay.o dhcp.o dns.o eth.o hashes.o helpers.o stacktsk.o lcdblocking.o tick.o main.o \
		ip.o udp.o udppt.o icmp.o
	$(LD) $(LDFLAGS) build/helpers.o build/stacktsk.o build/tick.o build/lcdblocking.o \
	build/main.o build/announce.o build/arp.o build/delay.o build/dhcp.o build/dns.o build/eth.o \
	build/hashes.o build/udp.o build/ip.o build/udppt.o build/icmp.o -o build/main.hex
	cp build/main.hex .

main.o: main.c build
	$(CC) $(CFLAGS) main.c -o build/main.o

tick.o: ../TCPIP_Stack/Tick.c build
	$(CC) $(CFLAGS) ../TCPIP_Stack/Tick.c -o build/tick.o

lcdblocking.o: ../TCPIP_Stack/LCDBlocking.c build
	$(CC) $(CFLAGS) ../TCPIP_Stack/LCDBlocking.c -o build/lcdblocking.o

stacktsk.o: ../TCPIP_Stack/StackTsk.c build
	$(CC) $(CFLAGS) ../TCPIP_Stack/StackTsk.c -o build/stacktsk.o

helpers.o: ../TCPIP_Stack/Helpers.c build
	$(CC) $(CFLAGS) ../TCPIP_Stack/Helpers.c -o build/helpers.o

announce.o: ../TCPIP_Stack/Announce.c build
	$(CC) $(CFLAGS) ../TCPIP_Stack/Announce.c -o build/announce.o

arp.o: ../TCPIP_Stack/ARP.c build
	$(CC) $(CFLAGS) ../TCPIP_Stack/ARP.c -o build/arp.o

delay.o: ../TCPIP_Stack/Delay.c build
	$(CC) $(CFLAGS) ../TCPIP_Stack/Delay.c -o build/delay.o

dhcp.o: ../TCPIP_Stack/DHCP.c build
	$(CC) $(CFLAGS) ../TCPIP_Stack/DHCP.c -o build/dhcp.o

dns.o: ../TCPIP_Stack/DNS.c build
	$(CC) $(CFLAGS) ../TCPIP_Stack/DNS.c -o build/dns.o

eth.o: ../TCPIP_Stack/ETH97J60.c build
	$(CC) $(CFLAGS) ../TCPIP_Stack/ETH97J60.c -o build/eth.o

hashes.o: ../TCPIP_Stack/Hashes.c build
	$(CC) $(CFLAGS) ../TCPIP_Stack/Hashes.c -o build/hashes.o

udp.o: ../TCPIP_Stack/UDP.c build
	$(CC) $(CFLAGS) ../TCPIP_Stack/UDP.c -o build/udp.o

icmp.o: ../TCPIP_Stack/ICMP.c build
	$(CC) $(CFLAGS) ../TCPIP_Stack/ICMP.c -o build/icmp.o

ip.o: ../TCPIP_Stack/IP.c build
	$(CC) $(CFLAGS) ../TCPIP_Stack/IP.c -o build/ip.o

udppt.o: ../TCPIP_Stack/UDPPerformanceTest.c build
	$(CC) $(CFLAGS) ../TCPIP_Stack/UDPPerformanceTest.c -o build/udppt.o

build:
	mkdir build

cleanall: clean
clean :
	rm -rf build
	rm main.hex
